package com.pajk.user.service.login.question;



import java.util.List;





import java.util.Map;

import net.pocrd.core.ServiceException;
import net.pocrd.dubboext.DubboExtProperty;

import com.alibaba.common.lang.StringUtil;
import com.pajk.user.exception.UserServiceHttpCode;
import com.pajk.user.model.Answer;
import com.pajk.user.model.SafetyAnswers;
import com.pajk.user.model.SafetyQuestions.Physique;
import com.pajk.user.model.User;
import com.pajk.user.util.DateUtil;


public class AnswerGenerator {
	public static boolean getsafetyQuestions(User user,SafetyAnswers safetyAnswers,Map<String,String> userMap) {
		List<Answer> answers = safetyAnswers.answers;
		int count =0;
		if(answers != null) {
			for(int i=0;i<answers.size();i++) {
				Answer answer = answers.get(i);
				if(answer.result != null && StringUtil.isNotEmpty(answer.result.get(0))) {
					if(answer.templeteId == 1 && user.getBirthday() != null && answer.result.get(0).equals(DateUtil.format(user.getBirthday(),"yyyy-MM-dd"))) {
						count++;
					}else if(answer.templeteId == 2 && answer.result.get(0).equals(user.getGender().name())) {
						count++;
					}else if(answer.templeteId == 3 && answer.result.get(0).equals("-1")) {
						count++;
					}else if(answer.templeteId == 4 && Physique.valueOf(answer.result.get(0)).getNameCn().equals(user.getPhysique())) {
						count++;
					}else if(answer.templeteId == 5 && answer.result.get(0).equals(user.getHeight().toString())) {
					    count++;
					}else if(answer.templeteId == 6 && userMap != null && userMap.size()>0) {
						for(int j=0;j<answer.result.size();j++) {
							if(userMap.get(answer.result.get(j)) == null) {
								break;
							}
						}
						count++;
					}
				}
				
			}
		}
		if(answers.size() >=3 && count >=2) return true;
		if(answers.size()<3 && answers.size()>0 && count ==answers.size()) return true;
		DubboExtProperty.setErrorCode(UserServiceHttpCode.SAFETYEXAM_NOT_QUALIFIED);
		return false;
	}
}
